const getStatusName = status => {
  const obj = {
    0: {
      name: '通过',
      color: '#44D26E',
    },
    1: {
      name: '未通过',
      color: '#F56C6C',
    },
  };
  return (
    obj[status] || {
      name: '不通过',
      color: '#F56C6C',
    }
  );
};
const getTaskStatusName = status => {
  const obj = {
    0: {
      name: '数据加载中',
      color: '#43B4FF',
    },
    1: {
      name: '合同审核中',
      color: '#43B4FF',
    },
    2: {
      name: '数据加载中',
      color: '#43B4FF',
    },
    3: {
      name: '数据加载失败',
      color: '#F56C6C',
    },
    4: {
      name: '审核成功',
      color: '#44D26E',
    },
    5: {
      name: '审核失败',
      color: '#F56C6C',
    },
  };
  return (
    obj[status] || {
      name: '审核中',
      color: '#43B4FF',
    }
  );
};
//数据行列合并的组装
const handleMergeRow = data => {
  let ret = JSON.parse (JSON.stringify (data));
  let collection = {};
  let preIndex = -1;
  for (let i in ret) {
    // item = {
    //     "name": "Jim",
    //     "age": 18,
    //     "address": "Sydney",
    //     "date": "2016-10-03"
    // }
    let item = ret[i];
    item.source = {};
    for (let key in item) {
      if (key == 'source') {
        continue;
      }
      // 记录每个key
      // collection = {
      //     "name": {}
      // }
      if (!collection[key]) {
        collection[key] = {};
      }
      // 首项或者该项此列不等于上一项此列
      if (preIndex == -1 || ret[preIndex][key] != item[key]) {
        // 记录每个key对应的所有值以及其起始索引和出现次数
        // collection = {
        //     "name": {
        //         "Jim#0": {
        //             "firstIndex": 0,
        //             "count": 1
        //         }
        //     }
        // }
        collection[key][`${item[key]}#${i}`] = {
          firstIndex: i,
          count: 1,
        };
        // 标注该列的起源index
        item.source[key] = i;
      } else {
        // 通过上一项找到起源index
        let source = ret[preIndex].source[key];
        item.source[key] = source;
        // 合并该列的行数加1
        collection[key][`${item[key]}#${source}`].count += 1;
      }
    }
    preIndex = i;
  }
  // console.log (collection);
  for (let key in collection) {
    // items = {
    //     "Jim#0": {
    //         "firstIndex": "0",
    //         "count": 3
    //     },
    //     "Jon#3": {
    //         "firstIndex": "3",
    //         "count": 1
    //     }
    // }
    let items = collection[key];
    for (let itemkey in items) {
      // value = {
      //     "firstIndex": "0",
      //     "count": 3
      // }
      let value = items[itemkey];
      // 根据记录的起始索引设置该项的mergeRow
      // {
      //     "name": "Jim",
      //     "age": 18,
      //     "address": "Sydney",
      //     "date": "2016-10-03",
      //     "mergeRow": {
      //         "address": 1,
      //         "age": 1,
      //         "date": 1,
      //         "name": 3
      //     }
      // }
      if (!ret[value.firstIndex].mergeRow) {
        ret[value.firstIndex].mergeRow = {};
      }
      ret[value.firstIndex].mergeRow[key] = value.count;
    }
  }
  // console.log (ret);
  return ret;
};
export {getTaskStatusName, getStatusName, handleMergeRow};
